package com.pilipili.zeus.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pilipili.commonutils.Result;
import com.pilipili.zeus.educms.entity.CrmBanner;
import com.pilipili.zeus.educms.entity.vo.BannerQuery;
import com.pilipili.zeus.educms.service.CrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页banner表 前端控制器
 *
 * @author Unlimited_Blade_Works
 * @since 2021-05-30
 */
@RestController
@RequestMapping("/educms/bannerAdmin")
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;
    @ApiOperation(value = "添加数据")
    @PostMapping("addBanner")
    public Result add(@RequestBody CrmBanner banner){
        boolean save = bannerService.save(banner);
        return  save?Result.ok():Result.error();
    }
    @ApiOperation(value = "根据Id删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id){
        boolean removeResult = bannerService.removeById(id);
        return removeResult?Result.ok():Result.error();
    }
    @ApiOperation(value = "分页查询+条件")
    @GetMapping("pageList/{current}/{limit}")
    public Result pageList(@PathVariable long current,
                                @PathVariable long limit,
                                @RequestBody(required = false) BannerQuery query){
        Page<CrmBanner> page=new Page<>(current,limit);
        bannerService.pageQuery(page, query);
        List<CrmBanner> list = page.getRecords();
        long total = page.getTotal();
        return  Result.ok().data("total", total).data("list",list);
    }
    @ApiOperation(value = "更新数据")
    @PostMapping("update")
    public Result update(@RequestBody CrmBanner banner){
        boolean update = bannerService.updateById(banner);
        return update?Result.ok():Result.error();
    }
}

